package ThreadSecurityIssue;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class PocketMoney {
    private  int num = 100 ;
    private Lock lock = new ReentrantLock();


    public void getPocketMoney() {

         lock.lock();

            if(num > 0 ) {

                num --;
                System.out.println(Thread.currentThread().getName() + "抢到红包，还剩下红包个数" +  num);
            }else{

                System.out.println("红包已被领完");
            }

        lock.unlock();



    }

}
